#ifndef ROADFORM_H_
#define ROADFORM_H_

#include <FApp.h>
#include <FBase.h>
#include <FUi.h>
#include <FIo.h>
#include <FText.h>
#include "OpennavSearchServiceProvider.h"
#include "Opennav.h"

class RoadForm :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Ui::ITextEventListener,
	public Osp::Ui::ISlidableListEventListener,
	public Osp::Ui::ICustomItemEventListener,
	public IOpennavSearchServiceListener

{
public:
	RoadForm();
	virtual ~RoadForm() { }
	result Construct(OpennavSearchServiceProvider* searchService, OpennavMap* map);
protected:
	Osp::Ui::Controls::SlidableList *__pListRoad;
	Osp::Ui::Controls::EditField *__pSearchRoad;
	Osp::Ui::Controls::ScrollPanel *__pScrollPanel;
	Osp::Ui::Controls::CustomListItemFormat* __pCustomListItemFormat;
	static const int ROAD_NAME_ID  = 101;
	static const int WHERE_NAME_ID = 102;
	static const int ID_SOFTKEY_BACK = 101;
	static const int ID_BUTTON_EDITFIELD_DONE = 101;
	static const int ID_BUTTON_EDITFIELD_CLOSE = 102;
public:
	static const RequestId REQUEST_ID_SET_CITY = 201;
public:
	virtual result OnInitializing(void);
	virtual result OnTerminating(void);
	virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);
	virtual void OnTextValueChanged(const Osp::Ui::Control& source);
	virtual void OnTextValueChangeCanceled(const Osp::Ui::Control& source) { }
	// ISlidableListEventListener Members
	virtual void OnListPropertyRequested (const Osp::Ui::Control &source) { }
	virtual void OnLoadToTopRequested(const Osp::Ui::Control &source, int index, int numItems);
	virtual void OnLoadToBottomRequested (const Osp::Ui::Control &source, int index, int numItems);
	virtual void OnUnloadItemRequested(const Control& source, int index) { }
	virtual void OnItemStateChanged(const Osp::Ui::Control &source, int index, int itemId, int elementId, Osp::Ui::ItemStatus status) { }
	virtual void OnItemStateChanged(const Osp::Ui::Control &source, int index, int itemId, Osp::Ui::ItemStatus status);
	virtual void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs);
	// IOpennavSearchServiceListener
	void OnGeocodingRequestResultReceived(IOpennavSearchResult* result);

private:
	void PerformSearch();
	Osp::Base::String GetWhereCity(opennav::Road& road);
	OpennavSearchServiceProvider* __pSearchService;
	OpennavMap* __pMap;
	OpennavSearchRoadResult* __pCurrentResult;
	Osp::Base::Runtime::Mutex* __pLock;
	int __currentCityId;
};

#endif /* ROADFORM_H_ */
